<template>
  <div class="like-page">
     <van-list
      v-model="loading"
      :finished="finished"
      finished-text="----我是有底线的---"
      @load="onLoad"
    >

      <article-item
        v-for="item in list"
        :key="item.id"
        :item="item"
      ></article-item>
    </van-list>
  </div>
</template>

<script>
import { getOptListAPI } from '@/api/interview'
export default {
  name: 'like-page',
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      page: 1
    }
  },
  methods: {
    async onLoad () {
      // console.log('onLoad被调用了', this.loading)
      // 异步更新数据
      const res = await getOptListAPI({
        optType: 2,
        pageSize: 10,
        page: this.page

      })
      // console.log(res)
      // 每次加载完页码加1
      this.page++
      // console.log(res)
      // 把每一页展开加到数组来
      this.list.push(...res.data.rows)
      // 每次加载完把loading改为false,可以下次继续加载
      this.loading = false
      // 如果数组的总数量大于等于  服务器的总数量就代表加载完了
      if (this.list.length >= res.data.total) {
        this.finished = true
      }
    }
  }
}
</script>

<style lang="less" scoped>
.like-page {
  margin-bottom: 50px;
  margin-top: 44px;
}
</style>
